<?php


class mainClassAction extends Action
{
    /**
     *采购项目执行汇总
     * @Auther: lv
     * @Email: 578530370@qq.com
     * @Date: 2020/4/2 10:03
     */
    public function getProjectInfoListAjax()
    {
        $uid = $this->adminid;

        $page = $this->request('page', 1);
        $limit = $this->request('limit', 15);
        $type = $this->request("type");
        $sdate = $this->request("sdate");
        $edate = $this->request("edate");
        $comid = $this->request('comid');
        $projectadminer = $this->request("puid");
        $proxygov = $this->request('proxygov');
        $approveWhere = "1=1";
        $approveWhere .= "  and d.status IN (1, 0) and d.modeid = 94";
        if ($type) {
            if($type == '其它'){
                $approveWhere .= " and b.type= ''";
            }else{
                $approveWhere .= " and b.type='" . $type . "'";
            }
        }
        if ($comid) {
            $approveWhere .= " and b.comid = " . $comid;
        }
        if ($proxygov) {
            $approveWhere .= " and b.proxygov='" . $proxygov . "'";
        }
        if ($projectadminer) {
            $approveWhere .= " and b.projectadminer=" . $projectadminer;
        }
        if ($sdate) $approveWhere .= " and b.addtime >= '" . $sdate . "'";
        if ($edate) $approveWhere .= " and b.addtime <='" . $edate . "'";
        if(empty($sdate) && empty($edate)) $approveWhere .= " and b.addtime >= '".date('Y'). "-01-01 00:00:00'";

        if ($type || $proxygov) {
            $sql = "select b.id from [Q]zbcg_new_info as b left join [Q]company as c on b.comid=c.id left join [Q]admin as a on a.id = b.projectadminer inner join [Q]flow_bill as d on b.mid = d.mid where " . $approveWhere . ' group by b.id';
            $listSql = "select b.*,c.name as companyname,a.name as projecterName from [Q]zbcg_new_info as b left join [Q]company as c on b.comid=c.id left join [Q]admin as a on a.id = b.projectadminer inner join [Q]flow_bill as d on b.mid = d.mid where " . $approveWhere . ' group by b.id' . ' limit ' . ($page - 1) * $limit . ',' . $limit;
        } else if($comid) {
            $sql = "select b.id from [Q]zbcg_new_info as b inner join [Q]company as c on b.comid=c.id left join [Q]admin as a on a.id = b.projectadminer inner join [Q]flow_bill as d on b.mid = d.mid where " . $approveWhere . ' group by b.id';
            $listSql = "select b.*,c.name as companyname,a.name as projecterName from [Q]zbcg_new_info as b inner join [Q]company as c on b.comid=c.id left join [Q]admin as a on a.id = b.projectadminer inner join [Q]flow_bill as d on b.mid = d.mid where " . $approveWhere . ' group by b.id' . ' limit ' . ($page - 1) * $limit . ',' . $limit;
        }else if($projectadminer) {
            $sql = "select b.id from [Q]zbcg_new_info as b inner join [Q]company as c on b.comid=c.id inner join [Q]admin as a on a.id = b.projectadminer inner join [Q]flow_bill as d on b.mid = d.mid where " . $approveWhere . ' group by b.id';
            $listSql = "select b.*,c.name as companyname,a.name as projecterName from [Q]zbcg_new_info as b inner join [Q]company as c on b.comid=c.id inner join [Q]admin as a on a.id = b.projectadminer inner join [Q]flow_bill as d on b.mid = d.mid where " . $approveWhere . ' group by b.id' . ' limit ' . ($page - 1) * $limit . ',' . $limit;
        }else{
            $sql = "select b.id from [Q]zbcg_new_info as b left join [Q]company as c on b.comid=c.id left join [Q]admin as a on a.id = b.projectadminer inner join [Q]flow_bill as d on b.mid = d.mid where " . $approveWhere . ' group by b.id';
            $listSql = "select b.*,c.name as companyname,a.name as projecterName from [Q]zbcg_new_info as b left join [Q]company as c on b.comid=c.id left join [Q]admin as a on a.id = b.projectadminer inner join [Q]flow_bill as d on b.mid = d.mid where " . $approveWhere . ' group by b.id' . ' limit ' . ($page - 1) * $limit . ',' . $limit;
        }
        $number = $this->db->getall($sql);
        $list = $this->db->getall($listSql);
        $bacarr = array(
            'totalCount' => count($number),
            'rows' => $list
        );
        return json_encode($bacarr);
    }

    /**
     * 二级单位项目统计(管理员)
     * @url:/index.php?a=getCompanyList&m=main&d=report&ajaxbool=true
     * @Auther: lv
     * @Email: 578530370@qq.com
     * @Date: 2020/4/2 10:03
     */
    public function getCompanyListAjax()
    {
        $sdate = $this->request('sdate');
        $edate = $this->request('edate');
        $where = "1=1";
        $where .= " and c.status IN (1, 0) and c.modeid = 94";
        if ($sdate) $where .= " and b.addtime >= '".$sdate. " 00:00:00'";
        if ($edate) $where .= " and b.addtime <='". $edate. " 23:59:59'";
        if(empty($sdate) && empty($edate)) $where .= " and b.addtime >= '".date('Y'). "-01-01 00:00:00'";
        $Sql = "select DISTINCT b.id,a.id,a.name,count(b.id) as num from [Q]company as a left join [Q]zbcg_new_info as b on a.id = b.comid inner join [Q]flow_bill as c on c.mid = b.mid where ".$where." and c.modeid = 94 group by a.id,a.name";
        $list = $this->db->getall($Sql);
        $bacarr	= array(
            'totalCount'=> count($list),
            'rows'		=> $list
        );
        return json_encode($bacarr);
    }

    /**
     * 二级单位项目统计（员工）
     * @url:/index.php?a=getCompanyList&m=main&d=report&ajaxbool=true
     * @Auther: lv
     * @Email: 578530370@qq.com
     * @Date: 2020/4/2 10:03
     */
    public function getCompanyListsAjax()
    {
        $sdate = $this->request('sdate');
        $edate = $this->request('edate');
        $where = "1=1";
        $where .= " and c.status IN (1, 0) and c.modeid = 94 and b.projectadminer=".$this->adminid;
        if ($sdate) $where .= " and b.addtime >= '".$sdate. " 00:00:00'";
        if ($edate) $where .= " and b.addtime <='". $edate. " 23:59:59'";
        if(empty($sdate) && empty($edate)) $where .= " and b.addtime >= '".date('Y'). "-01-01 00:00:00'";
        $Sql = "select a.id,a.name,count(b.id) as num from [Q]company as a left join [Q]zbcg_new_info as b on a.id = b.comid left join [Q]flow_bill as c on c.mid = b.mid where ".$where." and c.modeid = 94 group by a.id,a.name";
        $list = $this->db->getall($Sql);
        $bacarr	= array(
            'totalCount'=> count($list),
            'rows'		=> $list
        );
        return json_encode($bacarr);
    }
}